import { mapState, mapMutations } from 'vuex'
import {
	toDate,toMD,
} from '../../config/util'

export default {
	name: 'datePanel',
	props:['type'],
	data() {
		return {
			
		}
	},
	computed: {
		...mapState([
			'Date',
		]),	
		date(){
			if(this.type == 'dep'){
				return this.Date.postDepDate;
			}
			if(this.type == 'arr'){
				return this.Date.postArrDate;
			}
		},
	},
	methods: {
		...mapMutations([
			'RECORD_DATE'
		]),
		prev(){
			var dayMs = -86400*1000;
			this.handle(dayMs);
		},
		next(){
			var dayMs = 86400*1000;
			this.handle(dayMs);
		},
		handle(dayMs){
			if(this.type == 'dep') var d = this.Date.postDepDate;
			if(this.type == 'arr') var d = this.Date.postArrDate;
			var ms = new Date(d).getTime()
			var result = ms + dayMs;
			var obj = {
				postVal:toDate(result),
				mdVal:toMD(result)
			}
			//更改vuex中的日期
			this.RECORD_DATE(obj);
			//通知父页面重新请求数据
			this.reload();
		},
		reload(){
			this.$emit('reload');
		},
		reChoose(){			
			this.$router.push({ path: '/date?from=shopping'});
		}
	},
	created() {
		//更改vuex中的日期类型
		this.RECORD_DATE(this.type);
	}
}